package cn.com.utt.common.protorpc;

import java.util.concurrent.TimeUnit;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.SimpleChannelInboundHandler;

@Sharable
public class DisconnectHandler extends SimpleChannelInboundHandler<ByteBuf> {
	private RPCClient client;

	public DisconnectHandler(RPCClient client) {
		this.client = client;
	}
	
	public DisconnectHandler(int a) {
		// TODO Auto-generated constructor stub
	}

	
	@Override
	public void channelInactive(ChannelHandlerContext ctx) throws Exception {
		System.out.println("disconnect");
		final EventLoopGroup eventLoop = ctx.channel().eventLoop();
		eventLoop.schedule(new Runnable() {
			@Override
			public void run() {
				client.connect();
			}
		}, 1L, TimeUnit.SECONDS);
		super.channelInactive(ctx);
	}

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
		// TODO Auto-generated method stub
		
	}

}
